package com.yy.watchmen

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log

class ApkInstallReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        when (intent.action) {
            Intent.ACTION_PACKAGE_ADDED,
            Intent.ACTION_PACKAGE_INSTALL,
            Intent.ACTION_PACKAGE_REPLACED -> {
                val packageName = intent.data?.encodedSchemeSpecificPart
                // 这里可以执行安装成功后的逻辑
                Log.d("ApkInstallReceiver", "Package installed: $packageName")
            }

            Intent.ACTION_PACKAGE_REMOVED -> {
                val packageName = intent.data?.encodedSchemeSpecificPart
                Log.d("ApkInstallReceiver", "Package removed: $packageName")
            }

            Intent.ACTION_PACKAGE_CHANGED -> {
                val packageName = intent.data?.encodedSchemeSpecificPart
                Log.d("ApkInstallReceiver", "Package changed: $packageName")
            }

        }
    }
}
